//
//  PersonNetService.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/12.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "ReceiveAddressNetwork.h"
#import "GFXNetworkHandle.h"

NSString * const CreateAddress = @"auth/receive/address/add";//新建收货地址
NSString * const AddressList = @"auth/receive/address/list";//地址列表
NSString * const ChangeDefaultAddress = @"auth/receive/address/update/default";//改变默认地址
NSString * const ModifyDetailAddress = @"auth/receive/address/update";//修改地址
NSString * const DeleteAddress = @"auth/receive/address/delete";//删除收货地址
NSString * const DefaultAddress = @"auth/receive/address/get/default";//默认收货地址
NSString * const ProvincesCities = @"area/list";//省市列表

@implementation ReceiveAddressNetwork

+ (void)createAddressWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:CreateAddress params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getAddressListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *addresses))response
{
    [[GFXNetworkHandle shareHandle]post:AddressList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                AddressModel *model = [AddressModel objectWithDict:dict];
                [arr addObject:model];
            }
            response(YES,json[@"message"],arr);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)changeDefaultAddressWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:ChangeDefaultAddress params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)modifyDetailAddressWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:ModifyDetailAddress params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)deleteAddressWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:DeleteAddress params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getDefaultAddressWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,AddressModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:DefaultAddress params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            AddressModel *addressModel = [AddressModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],addressModel);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getProvincesCitiesWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *provinces))response
{
    [[GFXNetworkHandle shareHandle]post:ProvincesCities params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *provinces = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                ProvincesModel *model = [ProvincesModel objectWithDict:dict];
                [provinces addObject:model];
            }
            response(YES,json[@"message"],provinces);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

@end
